package com.yxym.method;

public class ThreadMethod01 {
    public static void main(String[] args) throws InterruptedException {
        Y y = new Y();

        for (int i = 0; i <= 20; i++) {
            Thread.sleep(1000);//休眠1秒
            System.out.println("主线程" + i + "hi");
            if(i == 5){
                y.start();
                y.join();
                System.out.println("子线程结束啦...");
            }
        }
    }
}

class Y extends Thread {
    @Override
    public void run() {
        for(int i = 0; i <= 20; i++){
            try {
                Thread.sleep(100);//休眠0.1秒
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("子线程" + i + "hello");
        }
    }
}